package com.shakespace.artofandroid.chapter02.contentprovider

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper


class DBOpenHelper(context: Context?) :
    SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {

    val CREATE_USER_TABLE = """
        CREATE TABLE IF NOT EXISTS $USER_TABLE_NAME (_id INTEGER PRIMARY KEY , name TEXT)
    """

    val CREATE_BOOK_TABLE = """
        CREATE TABLE IF NOT EXISTS $BOOK_TABLE_NAME (_id INTEGER PRIMARY KEY , name TEXT , sex INT)
    """

    override fun onCreate(db: SQLiteDatabase?) {
        db?.execSQL(CREATE_USER_TABLE)
        db?.execSQL(CREATE_BOOK_TABLE)

    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    companion object {
        private val DB_NAME = "Book.db"
        private val DB_VERSION = 1
        private val BOOK_TABLE_NAME = "book"
        private val USER_TABLE_NAME = "user"
    }

}


